package com.itheima.DeptSrrivce.impl;

import com.itheima.Dao.DeptDao;
import com.itheima.DeptSrrivce.DeptSerivce;
import com.itheima.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Component
public class DempServiceimpl implements DeptSerivce{
    @Autowired
    private DeptDao deptDao;
    public List<Dept> queryDeptList(){
        List<String> lines=deptDao.queryDeptList();
        List<Dept> deptList=lines.stream().map(line->{
            String[] splits=line.split(",");
            Integer id=Integer.parseInt(splits[0]);
            String name=splits[1];
            LocalDateTime upDateTime=LocalDateTime.parse(splits[2],
                    DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new Dept(id,name,upDateTime);
        }).toList();
        return deptList;
    }
}
